/**
 * Created by Administrator on 2018/6/9.
 */
var $CertusFormAjax;
var $$scope;
var dataInit;
var companyCache;
// 组织架构列表数据
function projOutIn($scope,CertusJsonAjax){
    var projOutInColmn = [
        {
            id: 'createTime',
            title: '创建时间',
            width: 73,
            type: 'string',
            columnClass: 'text-center',
            resolution: function (value, record, column, grid, dataNo, columnNo) {
                if(record.createTime){
                    var date = new Date(record.createTime);
                    var content = $.fn.dlshouwen.grid.tools.dateFormat(date, "yyyy-MM-dd hh:mm");
                    return content;

                }
                return "";
            }
        }, {
            id: 'expenses',
            title: '支出',
            width: 45,
            type: 'string',
            columnClass: 'text-center',
        }, {
            id: 'flowCode',
            title: '流程编码',
            width: 73,
            type: 'string',
            columnClass: 'text-center',
        }, {
            id: 'flowState',
            title: '流程状态',
            width: 50,
            type: 'string',
            columnClass: 'text-center',
        }, {
            id: 'templateName',
            title: '流程名称',
            width: 100,
            type: 'string',
            columnClass: 'text-center',
        }, {
            id: 'income',
            title: '收入',
            width: 45,
            type: 'string',
            columnClass: 'text-center'
        },{
            id: 'projState',
            title: '项目状态',
            type: 'string',
            columnClass: 'text-center',
            resolution: function (value, record, column, grid, dataNo, columnNo) {
                if(record.projState){
                   var projState = record.projState;
                   if(projState == "1"){
                        //#1运行中2已关闭3已完结4已暂停
                       return "运行中";
                   }else if(projState == "2"){
                       return "已关闭";
                   }else if(projState == "3"){
                       return "已完结";
                   }else if(projState == "4"){
                       return "已暂停";
                   }
                }
                return "运行中";
            }
        },{
            id: 'inititorName',
            title: '创建人',
            type: 'string',
            columnClass: 'text-center',
        },{
            id: 'reason',
            title: '事由',
            type: 'string',
            columnClass: 'text-center',
        },{
            id: 'paymentDate',
            title: '付款日期',
            type: 'string',
            columnClass: 'text-center',
            resolution: function (value, record, column, grid, dataNo, columnNo) {
                if(record.paymentDate){
                    var date = new Date(record.paymentDate);
                    var content = $.fn.dlshouwen.grid.tools.dateFormat(date, "yyyy-MM-dd");
                    return content;
                }
                return "";
            }
        },{
            id: 'belongCompanyCode',
            title: '归属公司',
            type: 'string',
            columnClass: 'text-center',
            resolution:function(value,record,column,grid,dataNo,columnNo){
                if(record.belongCompanyCode){
                    var companyCode = record.belongCompanyCode;
                    if(companyCode == "STSJT"){
                        return "赛特斯集团";
                    }else if(companyCode == "STSGD"){
                        return "赛特斯广东";
                    }else if(companyCode == "HFKJ"){
                        return "浩方科技";
                    }else if(companyCode == "HFXX"){
                        return "浩方信息";
                    }else if(companyCode == "STSBJ"){
                        return "赛特斯北京";
                    }else if(companyCode == "STSNJ"){
                        return "赛特斯南京";
                    }
                }
                return "";
            }
        },{
            id: 'projName',
            title: '项目名称',
            type: 'string',
            columnClass: 'text-center',
        }];
    var dataInit2 = CertusJsonAjax.dataInit("listProjExpense",null,projOutInColmn,'projOutInContainer','projOutInToolBarContainer');
    $scope.$watch("search",function(newValue,oldValue,scope){
        if(newValue){
            dataInit2.parameters = $scope.search;
            dataInit2.refresh(true);
        }
    },true)

}

function deptListInit($scope, $route, CertusFormAjax, CertusJsonAjax, $location, $http, $compile) {
    //悬浮窗 显示
    // $scope.mouseoverDept = function(aa){
    //     CertusFormAjax.ajax("querySuperiorDepartment",{deptCode:aa},function(){
    //         $scope. = ;
    //         $scope.
    //     })
    // }

    $$scope = $scope;
    $CertusFormAjax = CertusFormAjax;
    $CertusJsonAjax = CertusJsonAjax;

    function deptList() {
        var deptColumns = [{
            id: 'departmentName',
            title: '部门名称',
            type: 'string',
            columnClass: 'text-center',
            resolution:function(value, record, column, grid, dataNo, columnNo){
                var content = '';
                content += '  ';
                // onmouseover="mouseOverDeptName(\''+ record.departmentCode+'\')" onmouseout="mouseLeaveDeptName(\''+record.departmentCode +'\')"
                content += '<a style="display: inline-block;width: 100%;" href="javascript:void(0);" onclick="mouseOverDeptName(\''+ record.departmentCode+'\')">'+record.departmentName+'</a>';
                content += '<label class="department'+record.departmentCode +'" style="margin:5px 0 0 0;"></label>';
                return content;
            }
        }, {
            id: 'principalName',
            title: '部门负责人',
            type: 'string',
            width: 100,
            columnClass: 'text-center',
        }, {
            id: 'superiorDepartname',
            title: '上级部门',
            type: 'string',
            columnClass: 'text-center',
        }, {
            id: 'companyName',
            title: '公司/事业部',
            type: 'string',
            columnClass: 'text-center',
            resolution:function(value, record, column, grid, dataNo, columnNo){
                for(var j in companyCache){
                    if (companyCache[j].companyCode == record.companyCode) {
                        return companyCache[j].companyName;
                    }
                }
            }
        }, {
            id: 'createTime',
            title: '提交时间',
            type: 'string',
            width: 150,
            columnClass: 'text-center',
            resolution: function (value, record, column, grid, dataNo, columnNo) {
                var date = new Date(record.createTime);
                var content = $.fn.dlshouwen.grid.tools.dateFormat(date, "yyyy-MM-dd hh:mm");
                return content;
            }
        }, 
        // {
        //     id: 'operation',
        //     title: '操作',
        //     width: 350,
        //     type: 'string',
        //     columnClass: 'text-center',
        //     resolution: function (value, record, column, grid, dataNo, columnNo) {
        //         var met = {
        //             'RSZX-YGLBC':"editDept(\'' + record.departmentCode + '\')",
        //             'RSZX-YGLBD':"deleteDept(\'' + record.departmentCode + '\',this)"
        //         }
        //         content =  CertusFormAjax.initOperateAutho($scope.autho,['RSZX-ZZJGC%edit','RSZX-ZZJGD%delete'],met,deptColumns);
        //         return content;
        //     }
        // }
    ];
        $CertusJsonAjax.ajaxNode("department","relatedCompanyName",{},function(res){
            companyCache = res;
            dataInit = CertusJsonAjax.dataInit("deptpageList", null, deptColumns, 'proContainer', 'proToolBarContainer');
        })
    }

    deptList();

    $scope.deleteDept = function (a) {
    }
}
function editDept(departmentCode) {
    window.location.href = "#/addDept/" + departmentCode;
}

function deleteDept(departmentCode, b) {
    layer.confirm("是否删除部门", {
        title: '提示',
        btn: ['是', '否'] //按钮
    }, function () {
        ajaxCertus("deleteDept", {departmentCode: departmentCode}, function () {
            dataInit.refresh(true);
            layer.closeAll();
        });
    });
}


function mouseOverDeptName(aa){
    $CertusFormAjax.ajax("querySuperiorDepartment",{deptCode:aa},function(res){
        // $$scope.show = true;

        var status = $(".department"+aa).text();
        var hidsh = $(".department"+aa).css('display');
        if(status == null || status == "" || status == undefined){
            // $(".department"+aa).show();
            $(".department"+aa).html(res.data);
            $(".department"+aa).css('display','inline-block');
        }else{
            if(hidsh != "none"){
                $(".department"+aa).hide();
            }else{
                $(".department"+aa).html(res.data);
                $(".department"+aa).css('display','inline-block');
            }
        }
    })
}

// function mouseLeaveDeptName(aa){
//     // $$scope.show = false;
//     $(".department"+aa).html('');
// }
